<template>
  <login-page class="login-page">
    <a-icon type="loading"></a-icon>
    <p>正在跳转...</p>
  </login-page>
</template>

<script>
import { LoginPage } from './style'

export default {
  name: 'login',
  components: {
    'login-page': LoginPage,
  },
  data () {
    return {
    }
  },
  mounted () {
    const { token } = this.$route.query
    if (token) {
      this.$store.commit('setToken', token)
      localStorage.setItem('token', token)
      Promise.all([
        this.$store.dispatch('getUserInfo'),
        this.$store.dispatch('getMenuAndPermissions'),
      ])
        .then(() => {
          this.$router.replace('/home')
        })
        .catch(() => {
          this.$router.replace('/home')
        })
    } else {
      this.$store.dispatch('logout')
    }
  },
  methods: {
  }
}
</script>
